package com.adamfass.tractorbeam;

import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;

public class Goal implements GameEntity {
  private final Box box;
  
  public Goal(Node rootNode, Vector3f position, float radius,
              ColorRGBA color, String name) {
    box = new Box(name, Vector3f.ZERO, radius, radius, 1);
    box.setModelBound(new BoundingBox());
    box.updateModelBound();
    
    final MaterialState materialState =
      DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
    materialState.setEnabled(true);
    materialState.setDiffuse(color);
    materialState.setAmbient(color);
    box.setRenderState(materialState);
    box.updateRenderState();
    
    rootNode.attachChild(box);
    
    box.setLocalTranslation(position);
    box.updateGeometricState(0, true);
  }
  
  public void beforeUpdate() {
  }
  
  public void update() {
    // TODO(afass): some kind of animation when ball hits goal?
  }
  
  public void cleanUp() {
    throw new RuntimeException("Goals should not be removed");
  }
  
  // Temporary for AI controller
  public Vector3f getWorldTranslation() {
    box.updateWorldVectors();
    return box.getWorldTranslation();
  }
}
